<?php
namespace app\admin\controller;
use \think\Controller;
use \think\Request;
use \think\facade\Session;

/*品牌*/
class Material extends Base
{  
    /*列表*/
	public function index(Request $request){
		   $this->check_session();
        /*左侧导航*/
        $data_get=$request->get()['nav'];
        $data=$this->navleft($data_get);
        $model=new \app\admin\model\Material();/*调用模型查询*/
        $model_data=$model->get_data();
        $data['data_list']=$model_data;
        $this->assign($data);
	      return $this->fetch();
	}

  public function change(Request $request){
       $this->check_session();
        /*左侧导航*/
        $data_get=$request->get();
        $data=$this->navleft($data_get['nav']);
        if(isset($data_get['id'])){
          $model=new \app\admin\model\Material();/*调用模型查询*/
          $model_data=$model->get_edit($data_get['id']);
          $data['data_list']=$model_data;
        }
        $this->assign($data);
        return $this->fetch();
  }

      /*执行 新增 或者 修改任务*/
  public function do_change(Request $request){
        $this->check_session();
        $data=$request->post();
        if(empty($data['material_name'])){
          $result=['status'=>'0','msg'=>'请填写材质名称'];
          return json($result);
        }
        $model=new \app\admin\model\Material();/*调用模型查询*/
        $get=$request->get();
        if(!empty($get['id'])){
          $model_data=$model->update_data($get['id'],$data['material_name'],$data['des']);
        }else{
          $model_data=$model->insert_data($data['material_name'],$data['des']);
        }
        if($model_data==1){
            $result=['status'=>'1','msg'=>'操作成功'];
            return json($result);
        }else{
            $result=['status'=>'0','msg'=>'操作失败系统错误'];
            return json($result);
        }    
    }


    
     /*删除*/
    public function del(Request $request){
        $this->check_session();
        $data=$request->post();
        if(empty($data['id'])){
            $result=['status'=>'0','msg'=>'操作有误'];
            return json($result);
        }
        $model=new \app\admin\model\Material();/*调用模型查询*/
        $model_data=$model->delete_data($data['id']);
        if($model_data!=1){
            $result=['status'=>'0','msg'=>'删除失败'];
            return json($result);
        }else{
            $result=['status'=>'1','msg'=>'删除成功'];
            return json($result);
        }
    }


}	